package animator.phantom.gui.modals;

/*
    Copyright Janne Liljeblad 2006,2007,2008

    This file is part of Phantom2D.

    Phantom2D is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Phantom2D is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Phantom2D.  If not, see <http://www.gnu.org/licenses/>.
*/

import animator.phantom.controller.GUIComponents;
import animator.phantom.gui.*;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;


//--- A collection class to create one-liner modal windows.
public class DialogTopPanel extends JPanel
{
	private static final Color BG_COLOR = GUIColors.darkerBlue;
	private static final Color TEXT_COLOR = Color.white;
	private static Font FONT = GUIResources.BOLD_FONT_14;

	private static final int CORNER_WIDTH = 20;
	private static final int TEXT_X = 15;
	private static final int TEXT_ROW_HEIGHT = 20;
	private static final int BASE_LINE = 15;

	private static final int TEXT_TOP_PAD = 10;
	private static final int TEXT_BOTTOM_PAD = 10;
	private static final int TEXT_WIDTH_PAD = 20;	

	private String[] lines;

	private  boolean w_set = false;

	public DialogTopPanel( String[] lines )
	{
		this.lines = lines;

		FontMetrics fm = getFontMetrics( FONT );
		int maxWidth = 0;
		for( int i = 0; i < lines.length; i++ )
			if( fm.stringWidth( lines[ i ] ) > maxWidth ) maxWidth = fm.stringWidth( lines[ i ] );
		maxWidth = maxWidth + TEXT_WIDTH_PAD;

		setPreferredSize( new Dimension( maxWidth, lines.length * TEXT_ROW_HEIGHT + TEXT_TOP_PAD + TEXT_BOTTOM_PAD ) );
	}

	public void paintComponent( Graphics g )
	{
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, 	RenderingHints.VALUE_ANTIALIAS_ON );

		//--- Draw bg
		g2.setColor( BG_COLOR );
		//--- Draw corners
		Ellipse2D.Double ellipse = new Ellipse2D.Double();
		ellipse.setFrame( 0, 0, CORNER_WIDTH, CORNER_WIDTH );
		g2.fill( ellipse );
		ellipse.setFrame( 0, getHeight() - CORNER_WIDTH, CORNER_WIDTH, CORNER_WIDTH );
		g2.fill( ellipse );
		ellipse.setFrame( getWidth() - CORNER_WIDTH, getHeight() - CORNER_WIDTH, CORNER_WIDTH, CORNER_WIDTH );
		g2.fill( ellipse );
		ellipse.setFrame( getWidth() - CORNER_WIDTH, 0, CORNER_WIDTH, CORNER_WIDTH );
		g2.fill( ellipse );
		//--- Draw main dark area
		Rectangle2D.Double rect = new Rectangle2D.Double();
		rect.setFrame(CORNER_WIDTH / 2.0, 0, getWidth() - CORNER_WIDTH, getHeight() );
		g2.fill( rect );
		rect.setFrame(0, CORNER_WIDTH / 2.0, CORNER_WIDTH, getHeight() - CORNER_WIDTH );
		g2.fill( rect );
		rect.setFrame( getWidth() - CORNER_WIDTH / 2.0, CORNER_WIDTH / 2.0, CORNER_WIDTH, getHeight() - CORNER_WIDTH );
		g2.fill( rect );

		//--- Draw text
		g2.setColor( TEXT_COLOR );
		g2.setFont( FONT );
		for( int i = 0; i < lines.length; i++ )
		{
			g2.drawString( lines[ i ], TEXT_X,  i * TEXT_ROW_HEIGHT + BASE_LINE + TEXT_TOP_PAD );
		}
	}

}//end class
